import React, { useState, useEffect } from 'react';
import Taro from '@tarojs/taro';
import SelectLayout from '@/components/SelectLayout/index';
import 'taro-ui/dist/style/components/float-layout.scss';
import './index.scss';

const activityCancleReason = (props) => {
  const [reasonList, setReasonList] = useState([]);
  const { isOpened, handleClose, handleSelected,source } = props
  useEffect(() => {
    if (isOpened && reasonList.length === 0) {
      Taro.$get('/order/after-sales/reasons',{orderSource:source}).then(ret=>{
        if (ret.content?.length > 0) {
          let reasonListDest = ret.content.map((item) => {
            return {
              value: item.name,
              code: item.id,
            };
          });
          setReasonList(reasonListDest);
        }
      })
    }
  }, [isOpened]);

  return (
    <SelectLayout
      isOpened={isOpened}
      reasonList={reasonList || []}
      title="请选择退款的原因"
      btnTxt="下一步"
      handleClose={handleClose}
      handleSelected={(item) => handleSelected(item.code,item)}
    />
  );
};
export default activityCancleReason;
